const express = require('express');
const router = express.Router();

// 引入各模块路由
const authRoutes = require('./auth');
const userRoutes = require('./users');
const diaryRoutes = require('./diaries');
const categoryRoutes = require('./categories');
const tagRoutes = require('./tags');
const uploadRoutes = require('./upload');
const statsRoutes = require('./stats');
const corsTestRoutes = require('./cors-test');
const userSettingsRoutes = require('./user-settings');
const searchRoutes = require('./search');
const exportRoutes = require('./export');

// API版本信息
router.get('/', (req, res) => {
  res.json({
    message: '日记系统 API',
    version: '1.0.0',
    status: 'running',
    timestamp: new Date().toISOString(),
    endpoints: {
      auth: '/api/auth',
      users: '/api/users',
      diaries: '/api/diaries',
      categories: '/api/categories',
      tags: '/api/tags',
      upload: '/api/upload',
      stats: '/api/stats',
      corsTest: '/api/cors-test',
      userSettings: '/api/user',
      search: '/api/search',
      export: '/api/export'
    }
  });
});

// 路由配置
router.use('/auth', authRoutes);
router.use('/users', userRoutes);
router.use('/diaries', diaryRoutes);
router.use('/categories', categoryRoutes);
router.use('/tags', tagRoutes);
router.use('/upload', uploadRoutes);
router.use('/stats', statsRoutes);
router.use('/cors-test', corsTestRoutes);
router.use('/user', userSettingsRoutes);
router.use('/search', searchRoutes);
router.use('/export', exportRoutes);

// API 404处理
router.use('*', (req, res) => {
  res.status(404).json({
    error: 'API接口不存在',
    path: req.originalUrl,
    method: req.method,
    timestamp: new Date().toISOString()
  });
});

module.exports = router; 